<?php
/* @var $this ApplicationController */
/* @var $model Application */
/* @var $form CActiveForm */
?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'application-form',
	'enableAjaxValidation'=>false,
	'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>

	<p class="note"><?php echo Yii::t('base','Fields with <span class="required">*</span> are required.');?></p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'application_name'); ?>
		<?php echo $form->textField($model,'application_name',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'application_name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'platform'); ?>
		<?php echo $form->dropDownList($model,'platform',array('0'=>'android','1'=>'ios'),array('class'=>'Application_platform')); ?>
		<?php echo $form->error($model,'platform'); ?>
	</div>
	<?php if($model->isNewRecord){?>
		<div id="applicationserver" style="display:none;">
			<div class="row">
			<?php echo $form->labelEx($model,'application_server_key'); ?>
			<?php echo $form->textField($model,'application_server_key',array('size'=>60,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'application_server_key'); ?>
			</div>
		</div>		
		<div id="applicationpem" style="display:none;">
			<div class="row">
			<?php echo $form->labelEx($model,'pem_file'); ?>
			<?php echo $form->fileField($model,'pem_file',array('size'=>60,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'pem_file'); ?>
			</div>
			<div class="row">
			<?php echo $form->labelEx($model,'pem_password'); ?>
			<?php echo $form->passwordField($model,'pem_password',array('size'=>60,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'pem_password'); ?>
			</div>
		</div>
	<?php }else{?>
		<?php if($model->platform==0){?>
		<div id="applicationserver">
			<div class="row">
			<?php echo $form->labelEx($model,'application_server_key'); ?>
			<?php echo $form->textField($model,'application_server_key',array('size'=>60,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'application_server_key'); ?>
			</div>
		</div>
		<div id="applicationpem" style="display:none;">
				<div class="row">
				<?php echo $form->labelEx($model,'pem_file'); ?>
				<?php echo $form->fileField($model,'pem_file',array('size'=>60,'maxlength'=>255)); ?>
				<?php echo $form->error($model,'pem_file'); ?>
				</div>
				<div class="row">
				<?php echo $form->labelEx($model,'pem_password'); ?>
				<?php echo $form->passwordField($model,'pem_password',array('size'=>60,'maxlength'=>255)); ?>
				<?php echo $form->error($model,'pem_password'); ?>
				</div>
		</div>
		<?php }?>
		<?php if($model->platform==1){?>
		<div id="applicationserver" style="display:none;">
				<div class="row">
				<?php echo $form->labelEx($model,'application_server_key'); ?>
				<?php echo $form->textField($model,'application_server_key',array('size'=>60,'maxlength'=>255)); ?>
				<?php echo $form->error($model,'application_server_key'); ?>
				</div>
		</div>
			<div id="applicationpem">
					<div class="row">
					<?php echo $form->labelEx($model,'pem_file'); ?>
					<input type="text" name="pem_file" value="<?php echo $model->pem_file;?>" readonly=true/>
					<?php echo $form->fileField($model,'pem_file',array('size'=>60,'maxlength'=>255,'value'=>$model->pem_file)); ?>
					<?php echo $form->error($model,'pem_file'); ?>
					</div>
					<div class="row">
					<?php echo $form->labelEx($model,'pem_password'); ?>
					<?php echo $form->passwordField($model,'pem_password',array('size'=>60,'maxlength'=>255)); ?>
					<?php echo $form->error($model,'pem_password'); ?>
					</div>
			</div>
			<?php }?>
		<?php }?>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('base','Create') : Yii::t('base','Save')); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php
Yii :: app()->clientScript->registerScript('search', "
			$('.Application_platform').change(function(){
			var platform=$(this).val();
			if(platform==0){
				$('#applicationserver').show();
				$('#applicationpem').hide();	
			}if(platform==1){
				$('#applicationpem').show();
				$('#applicationserver').hide();		
			}
		});
				");
?>